#include "IpPortParam.h"

QString CIpPortParam::GetIpText()
{
    return QString("%1.%2.%3.%4")
        .arg(uaFieldA).arg(uaFieldB)
        .arg(uaFieldC).arg(uaFieldD);
}

QString CIpPortParam::GetIpPortText()
{
    return QString("%1.%2.%3.%4:%5")
        .arg(uaFieldA).arg(uaFieldB)
        .arg(uaFieldC).arg(uaFieldD)
        .arg(usPort);
}

void CIpPortParam::FromIp(const QString& strIp)
{
    if (strIp.isEmpty())
    {
        return;
    }

    QStringList listFields = strIp.split("."); //a.b.c.d
    if (4 != listFields.count())
    {
        return;
    }

    uaFieldA = (quint8) listFields.at(0).toUInt();
    uaFieldB = (quint8) listFields.at(1).toUInt();
    uaFieldC = (quint8) listFields.at(2).toUInt();
    uaFieldD = (quint8) listFields.at(3).toUInt();
}
